using System;
using System.Collections.Generic;
using System.Linq;
using ProjectEuler.Core.Helpers;

namespace ProjectEuler.Core
{
    public class Problem36 : IProjectEulerProblem
    {
        protected IEnumerable<int> PalindromicNumbersInBase10AndBase2LessThan(int n)
        {
            for (int i = 1; i < n; i++)
            {
                string base10string = i.ToString();

                if (base10string.IsPalindrome())
                {
                    string base2string = Convert.ToString(i, 2);
                    if (base2string.IsPalindrome())
                    {
                        yield return i;
                    }
                }
            }
        }

        public int Number
        {
            get { return 36; }
        }

        public string Description
        {
            get { return "Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2."; }
        }

        public string Answer
        {
            get { return PalindromicNumbersInBase10AndBase2LessThan(1000000).Sum().ToString(); }
        }
    }
}